﻿using System;

namespace Text0401
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("请输入n的值");
            int n = Convert.ToInt32(Console.ReadLine());
            sumFac(n);
            asumFac(n);
            Console.WriteLine(asumFac(n));
        }

        //3.求sumFac(1) + sumFac(2) + sumFac(3) +…..+sumFac(n)
        //         1!     +   1!+2!       +    3!+2!+1!

        //阶层
        static int fac(int n)
        {
            int acc = 1;
            for (int i = 1; i <= n; i++)
            {
                acc *= i;
            }
            return acc;
        }

        //阶层和
        static int sumFac(int n)
        {
            int sum = 0;
            for (int i = 1; i <= n; i++){
                sum += fac(i);
            }
            return sum;
        }       

        //阶层和的和
        static int asumFac(int n)
        {
            int asum = 0;
            for (int  i = 1; i<=n; i++)
            {
                asum += sumFac(i);
            }
            return asum;
        }
    }
}
